<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取可用的加密算法</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.openssl-get-cert-locations.html">« openssl_get_cert_locations</a></li>
      <li style="float: right;"><a href="function.openssl-get-curve-names.html">openssl_get_curve_names »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.openssl.html">OpenSSL 函数</a></li>
    <li>获取可用的加密算法</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.openssl-get-cipher-methods" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_get_cipher_methods</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_get_cipher_methods</span> &mdash; <span class="dc-title">获取可用的加密算法</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.openssl-get-cipher-methods-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_get_cipher_methods</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$aliases</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   获取可用的加密算法的列表。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-get-cipher-methods-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">aliases</code></dt>

     <dd>

      <p class="para">
       如果密码别名应该包含在返回的<span class="type">array</span>中，则设置为 <strong><code>true</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-get-cipher-methods-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   包含可用加密算法的<span class="type">array</span>。
   请注意：在 OpenSSL 1.1.1 版本之前，返回加密算法的拼法大小写都有；
   从 OpenSSL 1.1.1 开始，统一只返回小写的形式。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-get-cipher-methods-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-939">
    <p><strong>示例 #1 <span class="function"><strong>openssl_get_cipher_methods()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     展示了哪些加密算法能被找到，哪些别名可用。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ciphers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_cipher_methods</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$ciphers_and_aliases&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">openssl_get_cipher_methods</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$cipher_aliases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$ciphers_and_aliases</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//ECB&nbsp;mode&nbsp;should&nbsp;be&nbsp;avoided<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$n</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$n</span><span style="color: #007700">,</span><span style="color: #DD0000">"ecb"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /><br /></span><span style="color: #FF8000">//At&nbsp;least&nbsp;as&nbsp;early&nbsp;as&nbsp;Aug&nbsp;2016,&nbsp;Openssl&nbsp;declared&nbsp;the&nbsp;following&nbsp;weak:&nbsp;RC2,&nbsp;RC4,&nbsp;DES,&nbsp;3DES,&nbsp;MD5&nbsp;based<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"des"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"rc2"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"rc4"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$ciphers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">,&nbsp;function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"md5"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$cipher_aliases&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(</span><span style="color: #0000BB">$cipher_aliases</span><span style="color: #007700">,function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"des"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /></span><span style="color: #0000BB">$cipher_aliases&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_filter</span><span style="color: #007700">(</span><span style="color: #0000BB">$cipher_aliases</span><span style="color: #007700">,function(</span><span style="color: #0000BB">$c</span><span style="color: #007700">)&nbsp;{&nbsp;return&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$c</span><span style="color: #007700">,</span><span style="color: #DD0000">"rc2"</span><span style="color: #007700">)===</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;}&nbsp;);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ciphers</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$cipher_aliases</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; aes-128-cbc
    [1] =&gt; aes-128-cbc-hmac-sha1
    [2] =&gt; aes-128-cbc-hmac-sha256
    [3] =&gt; aes-128-ccm
    [4] =&gt; aes-128-cfb
    [5] =&gt; aes-128-cfb1
    [6] =&gt; aes-128-cfb8
    [7] =&gt; aes-128-ctr
    [9] =&gt; aes-128-gcm
    [10] =&gt; aes-128-ocb
    [11] =&gt; aes-128-ofb
    [12] =&gt; aes-128-xts
    [13] =&gt; aes-192-cbc
    [14] =&gt; aes-192-ccm
    [15] =&gt; aes-192-cfb
    [16] =&gt; aes-192-cfb1
    [17] =&gt; aes-192-cfb8
    [18] =&gt; aes-192-ctr
    [20] =&gt; aes-192-gcm
    [21] =&gt; aes-192-ocb
    [22] =&gt; aes-192-ofb
    [23] =&gt; aes-256-cbc
    [24] =&gt; aes-256-cbc-hmac-sha1
    [25] =&gt; aes-256-cbc-hmac-sha256
    [26] =&gt; aes-256-ccm
    [27] =&gt; aes-256-cfb
    [28] =&gt; aes-256-cfb1
    [29] =&gt; aes-256-cfb8
    [30] =&gt; aes-256-ctr
    [32] =&gt; aes-256-gcm
    [33] =&gt; aes-256-ocb
    [34] =&gt; aes-256-ofb
    [35] =&gt; aes-256-xts
    [36] =&gt; aria-128-cbc
    [37] =&gt; aria-128-ccm
    [38] =&gt; aria-128-cfb
    [39] =&gt; aria-128-cfb1
    [40] =&gt; aria-128-cfb8
    [41] =&gt; aria-128-ctr
    [43] =&gt; aria-128-gcm
    [44] =&gt; aria-128-ofb
    [45] =&gt; aria-192-cbc
    [46] =&gt; aria-192-ccm
    [47] =&gt; aria-192-cfb
    [48] =&gt; aria-192-cfb1
    [49] =&gt; aria-192-cfb8
    [50] =&gt; aria-192-ctr
    [52] =&gt; aria-192-gcm
    [53] =&gt; aria-192-ofb
    [54] =&gt; aria-256-cbc
    [55] =&gt; aria-256-ccm
    [56] =&gt; aria-256-cfb
    [57] =&gt; aria-256-cfb1
    [58] =&gt; aria-256-cfb8
    [59] =&gt; aria-256-ctr
    [61] =&gt; aria-256-gcm
    [62] =&gt; aria-256-ofb
    [63] =&gt; bf-cbc
    [64] =&gt; bf-cfb
    [66] =&gt; bf-ofb
    [67] =&gt; camellia-128-cbc
    [68] =&gt; camellia-128-cfb
    [69] =&gt; camellia-128-cfb1
    [70] =&gt; camellia-128-cfb8
    [71] =&gt; camellia-128-ctr
    [73] =&gt; camellia-128-ofb
    [74] =&gt; camellia-192-cbc
    [75] =&gt; camellia-192-cfb
    [76] =&gt; camellia-192-cfb1
    [77] =&gt; camellia-192-cfb8
    [78] =&gt; camellia-192-ctr
    [80] =&gt; camellia-192-ofb
    [81] =&gt; camellia-256-cbc
    [82] =&gt; camellia-256-cfb
    [83] =&gt; camellia-256-cfb1
    [84] =&gt; camellia-256-cfb8
    [85] =&gt; camellia-256-ctr
    [87] =&gt; camellia-256-ofb
    [88] =&gt; cast5-cbc
    [89] =&gt; cast5-cfb
    [91] =&gt; cast5-ofb
    [92] =&gt; chacha20
    [93] =&gt; chacha20-poly1305
    [111] =&gt; id-aes128-CCM
    [112] =&gt; id-aes128-GCM
    [113] =&gt; id-aes128-wrap
    [114] =&gt; id-aes128-wrap-pad
    [115] =&gt; id-aes192-CCM
    [116] =&gt; id-aes192-GCM
    [117] =&gt; id-aes192-wrap
    [118] =&gt; id-aes192-wrap-pad
    [119] =&gt; id-aes256-CCM
    [120] =&gt; id-aes256-GCM
    [121] =&gt; id-aes256-wrap
    [122] =&gt; id-aes256-wrap-pad
    [124] =&gt; idea-cbc
    [125] =&gt; idea-cfb
    [127] =&gt; idea-ofb
    [137] =&gt; seed-cbc
    [138] =&gt; seed-cfb
    [140] =&gt; seed-ofb
    [141] =&gt; sm4-cbc
    [142] =&gt; sm4-cfb
    [143] =&gt; sm4-ctr
    [145] =&gt; sm4-ofb
)
Array
(
    [36] =&gt; aes128
    [37] =&gt; aes128-wrap
    [38] =&gt; aes192
    [39] =&gt; aes192-wrap
    [40] =&gt; aes256
    [41] =&gt; aes256-wrap
    [69] =&gt; aria128
    [70] =&gt; aria192
    [71] =&gt; aria256
    [72] =&gt; bf
    [77] =&gt; blowfish
    [99] =&gt; camellia128
    [100] =&gt; camellia192
    [101] =&gt; camellia256
    [102] =&gt; cast
    [103] =&gt; cast-cbc
    [146] =&gt; idea
    [164] =&gt; seed
    [169] =&gt; sm4
)

</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.openssl-get-cipher-methods-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.openssl-get-md-methods.html" class="function" rel="rdfs-seeAlso">openssl_get_md_methods()</a> - 获取可用的摘要算法</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>